home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Complete Linux
/
Complete Linux.iso
/
xwindows
/
demos
/
xfract_1.z
/
xfract_1
/
xfractint-1.06
/
miscres.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-28
|
24KB
|
907 lines
/*
Resident odds and ends that don't fit anywhere else.
*/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <time.h>
#ifndef XFRACT
#include <stdarg.h>
#include <io.h>
#else
#include <varargs.h>
#endif
#include <math.h>
#ifdef __TURBOC__
#include <dir.h>
#endif
#include "fractint.h"
#include "fractype.h"
#include "helpdefs.h"
#include "prototyp.h"
/* routines in this module */
#ifndef XFRACT
extern int timer(int timertype,int(*subrtn)(),...);
#else
extern int timer();
#endif
static void trigdetails(char *);
int active_ovly = -1;
long timer_start,timer_interval; /* timer(...) start & total */
extern char IFSFileName[80];
extern char IFSName[40];
extern float far *ifs_defn;
extern int ifs_changed;
extern int ifs_type;
extern char temp[], temp1[256]; /* temporary strings */
extern int active_ovly;
extern int xdots, ydots;
extern int dotmode;
extern int show_orbit;
extern int timerflag;
extern int debugflag;
extern int maxit;
extern int fractype;
extern int got_status,curpass,totpasses,currow,curcol;
extern int fileydots;
extern int xxstart,xxstop,yystart,yystop;
extern int display3d;
extern char overwrite;
/* TW's static string consolidation campaign to help brain-dead compilers */
char s_cantopen[] = {"Can't open %s"};
char s_cantwrite[] = {"Can't write %s"};
char s_cantcreate[] = {"Can't create %s"};
char s_cantunderstand[] = {"Can't understand %s"};
char s_cantfind[] = {"Can't find %s"};
/* call next when returning from resident routine and unsure whether
caller is an overlay which has been displaced */
void restore_active_ovly()
{
switch (active_ovly) {
case OVLY_MISCOVL: miscovl_overlay(); break;
case OVLY_CMDFILES: cmdfiles_overlay(); break;
case OVLY_HELP: help_overlay(); break;
case OVLY_PROMPTS: prompts_overlay(); break;
case OVLY_LOADFILE: loadfile_overlay(); break;
case OVLY_ROTATE: rotate_overlay(); break;
case OVLY_PRINTER: printer_overlay(); break;
case OVLY_LINE3D: line3d_overlay(); break;
case OVLY_ENCODER: encoder_overlay(); break;
case OVLY_CALCFRAC: calcfrac_overlay(); break;
case OVLY_INTRO: intro_overlay(); break;
}
}
#ifndef XFRACT
void findpath(char *filename, char *fullpathname) /* return full pathnames */
{
if (filename[0] == SLASHC
|| (filename[0] && filename[1] == ':')) {
strcpy(fullpathname,filename);
return;
}
fullpathname[0] = 0; /* indicate none found */
#ifdef __TURBOC__ /* look for the file */
strcpy(fullpathname,searchpath(filename));
#else
_searchenv(filename,"PATH",fullpathname);
#endif
if (fullpathname[0] != 0) /* found it! */
if (strncmp(&fullpathname[2],SLASHSLASH,2) == 0) /* stupid klooge! */
strcpy(&fullpathname[3],filename);
}
#endif
void notdiskmsg()
{
static char far sorrymsg[]={
"I'm sorry, but because of its random-screen-access algorithms, this\n\
type cannot be created using a real-disk based 'video' mode."};
stopmsg(1,sorrymsg);
}
/* convert corners to center/mag */
int cvtcentermag(double *Xctr, double *Yctr, double *Magnification)
{
extern double xxmax,xxmin,yymax,yymin,xx3rd,yy3rd;
double Width, Height, Radius, Ratio;
Width = xxmax - xxmin;
Height = yymax - yymin;
Ratio = Height / Width;
if(xx3rd != xxmin || yy3rd != yymin || Width < 0
|| (Width > 1e-8 && (Ratio <= 0.74 || Ratio >= 0.76))
|| Ratio < 0.66 || Ratio > 0.84)
return(0);
/* calculate center and magnification */
Radius = Height / 2.0;
*Xctr = xxmin + (Width / 2.0);
*Yctr = yymin + Radius;
*Magnification = 1.0 / Radius;
return(1);
}
void updatesavename(char *filename) /* go to the next file name */
{
char *save, *hold;
char name[80],suffix[80];
char *dotptr;
strcpy(name,filename);
suffix[0] = 0;
if ((dotptr = strrchr(name,'.')) != NULL
&& dotptr > strrchr(name,SLASHC)) {
strcpy(suffix,dotptr);
*dotptr = 0;
}
hold = name + strlen(name) - 1; /* start at the end */
while(hold >= name && (*hold == ' ' || isdigit(*hold))) /* skip backwards */
hold--;
hold++; /* recover first digit */
while (*hold == '0') /* skip leading zeros */
hold++;
save = hold;
while (*save) { /* check for all nines */
if (*save != '9')
break;
save++;
}
if (!*save) /* if the whole thing is nines then back */
save = hold - 1; /* up one place. Note that this will eat */
/* your last letter if you go to far. */
else
save = hold;
sprintf(save,"%d",atoi(hold)+1); /* increment the number */
strcpy(filename,name);
strcat(filename,suffix);
}
int check_writefile(char *name,char *ext)
{
/* after v16 release, change encoder.c to also use this routine */
char openfile[80];
char opentype[20];
int i;
nextname:
strcpy(openfile,name);
strcpy(opentype,ext);
for (i = 0; i < strlen(openfile); i++)
if (openfile[i] == '.') {
strcpy(opentype,&openfile[i]);
openfile[i] = 0;
}
strcat(openfile,opentype);
if (access(openfile,0) != 0) /* file doesn't exist */
{
strcpy(name,openfile);
return 0;
}
/* file already exists */
if (overwrite == 0) {
updatesavename(name);
goto nextname;
}
return 1;
}
int check_key()
{
int key;
if((key = keypressed()) != 0) {
if(key != 'o' && key != 'O') {
fflush(stdout);
return(-1);
}
getakey();
if (dotmode != 11)
show_orbit = 1 - show_orbit;
}
return(0);
}
/* timer function:
timer(0,(*fractal)()) fractal engine
timer(1,NULL,int width) decoder
timer(2) encoder
*/
#ifndef XFRACT
int timer(int timertype,int(*subrtn)(),...)
#else
int timer(va_alist)
va_dcl
#endif
{
va_list arg_marker; /* variable arg list */
char *timestring;
time_t ltime;
FILE *fp;
int out;
int i;
int do_bench;
#ifndef XFRACT
va_start(arg_marker,subrtn);
#else
int timertype;
int (*subrtn)();
va_start(arg_marker);
timertype = va_arg(arg_marker, int);
subrtn = ( int (*)()) va_arg(arg_marker, int);
#endif
do_bench = timerflag; /* record time? */
if (timertype == 2) /* encoder, record time only if debug=200 */
do_bench = (debugflag == 200);
if(do_bench)
fp=fopen("bench","a");
timer_start = clock_ticks();
switch(timertype) {
case 0:
out = (*subrtn)();
break;
case 1:
i = va_arg(arg_marker,int);
out = decoder(i); /* not indirect, safer with overlays */
break;
case 2:
out = encoder(); /* not indirect, safer with overlays */
break;
}
/* next assumes CLK_TCK is 10^n, n>=2 */
timer_interval = (clock_ticks() - timer_start) / (CLK_TCK/100);
if(do_bench) {
time(<ime);
timestring = ctime(<ime);
timestring[24] = 0; /*clobber newline in time string */
switch(timertype) {
case 1:
fprintf(fp,"decode ");
break;
case 2:
fprintf(fp,"encode ");
break;
}
fprintf(fp,"%s type=%s resolution = %dx%d maxiter=%d",
timestring,
curfractalspecific->name,
xdots,
ydots,
maxit);
fprintf(fp," time= %ld.%02ld secs\n",timer_interval/100,timer_interval%100);
if(fp != NULL)
fclose(fp);
}
return(out);
}
BYTE trigndx[] = {SIN,SQR,SINH,COSH};
#ifndef XFRACT
void (*ltrig0)() = lStkSin;
void (*ltrig1)() = lStkSqr;
void (*ltrig2)() = lStkSinh;
void (*ltrig3)() = lStkCosh;
void (*mtrig0)() = mStkSin;
void (*mtrig1)() = mStkSqr;
void (*mtrig2)() = mStkSinh;
void (*mtrig3)() = mStkCosh;
#endif
void (*dtrig0)() = dStkSin;
void (*dtrig1)() = dStkSqr;
void (*dtrig2)() = dStkSinh;
void (*dtrig3)() = dStkCosh;
struct trig_funct_lst trigfn[] =
/* changing the order of these alters meaning of *.fra file */
/* maximum 6 characters in function names or recheck all related code */
{
#ifndef XFRACT
{"sin", lStkSin, dStkSin, mStkSin },
{"cosxx", lStkCosXX, dStkCosXX, mStkCosXX },
{"sinh", lStkSinh, dStkSinh, mStkSinh },
{"cosh", lStkCosh, dStkCosh, mStkCosh },
{"exp", lStkExp, dStkExp, mStkExp },
{"